Add option to include InstanceId in Application Insights operation name #3266
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a new configuration option
IncludeInstanceIdInOperationNamethat allows users to include the Durable Orchestration Instance ID in the Application Insights operation name (operation_Name). This addresses a significant observability gap in the .NET Isolated worker model.Problem
When using Durable Functions with Application Insights in the .NET Isolated worker model, all orchestrations appear under the same Operation Name in the Application Insights Failures tab. When multiple orchestrations fail simultaneously, failures are aggregated together, making it extremely difficult to diagnose which specific orchestration instance failed without manually drilling down into each sample.
Why TelemetryInitializer doesn't work in Isolated Model
In the in-process model, users could implement
ITelemetryInitializerto modify the operation name because:RequestTelemetryIn the isolated worker model, this approach fails because:
ITelemetryInitializerin the worker process cannot intercept host-generated telemetrySolution
This PR modifies the telemetry at the source in the host extension, adding the instance ID to the operation name before it's sent to Application Insights.
Changes
TraceOptions.cs - Added new configuration property:
Schema.cs - Added overloads to
SpanNamesmethods that accept instance ID:CreateOrchestration(name, version, instanceId, includeInstanceId)CallOrSignalEntity(name, operation, instanceId, includeInstanceId)EntityStartsAnOrchestration(name, instanceId, includeInstanceId)TraceHelper.cs - Updated
StartActivityForNewOrchestrationto accept and use the configurationWebJobsTelemetryModule.cs - Added setting
Context.Operation.Namefor V2 distributed tracingHttpApiHandler.cs & TaskHubGrpcServer.cs - Pass configuration when creating orchestration activities
SchemaSpanNamesTests.cs - Added 15 unit tests
Usage
Users can enable this feature in
host.json:{ "version": "2.0", "extensions": { "durableTask": { "tracing": { "DistributedTracingEnabled": true, "Version": "V2", "IncludeInstanceIdInOperationName": true } } } }Result
When enabled, the operation name changes from:
create_orchestration:MyOrchestrationTo:
create_orchestration:MyOrchestration (abc123-def456-ghi789)This allows Application Insights to group failures by individual orchestration instance.
Breaking Changes
None. This is a purely additive change:
falseIssue describing the changes in this PR
resolves #3258
Pull request checklist
pending_docs.mdrelease_notes.md/src/Worker.Extensions.DurableTask/AssemblyInfo.cs